package com.yanqu.road.server.gameplayer.module.player;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.UserActivityConditionData;
import com.yanqu.road.entity.log.LogVipExp;
import com.yanqu.road.entity.player.UserPassRoad;
import com.yanqu.road.entity.player.UserSubscribe;
import com.yanqu.road.entity.recharge.*;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.*;
import com.yanqu.road.entity.log.LogUserRechargeTimes;
import com.yanqu.road.entity.recharge.FindActivityResult;
import com.yanqu.road.entity.recharge.RechargeOrder;
import com.yanqu.road.entity.recharge.ThirdPartyRechargeOrder;
import com.yanqu.road.entity.task.args.ManorRechargeArgs;
import com.yanqu.road.entity.task.args.RechargeDaysArgs;
import com.yanqu.road.entity.task.args.union.UnionRechargeUserArgs;
import com.yanqu.road.logic.bussiness.player.SubscribeBussiness;
import com.yanqu.road.logic.bussiness.recharge.RechargeBussiness;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.logic.pb.RechargePb;
import com.yanqu.road.pb.recharge.RechargeProto;
import com.yanqu.road.pb.subscribe.SubscribeProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityMallModule;
import com.yanqu.road.server.gameplayer.module.activity.ActivityModule;
import com.yanqu.road.server.gameplayer.module.activity.zhanling.ZhanLingActivityModule;
import com.yanqu.road.server.gameplayer.module.banquet.BanquetModule;
import com.yanqu.road.server.gameplayer.module.base.GeneralModule;
import com.yanqu.road.server.gameplayer.module.passRoad.PassRoadModule;
import com.yanqu.road.server.gameplayer.module.recharge.RechargeGainModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.recharge.potential.PotentialArg;
import com.yanqu.road.server.logic.mail.MailManager;
import com.yanqu.road.server.logic.recharge.BaseRecharge;
import com.yanqu.road.server.logic.recharge.IngotsRechargeThirdDouble;
import com.yanqu.road.server.logic.recharge.RechargeManager;
import com.yanqu.road.server.logic.recharge.limit.BaseRMBMallLimit;
import com.yanqu.road.server.logic.recharge.limit.MallLimitFactory;
import com.yanqu.road.server.manger.DataAnalyticsMgr;
import com.yanqu.road.server.manger.MultipleLanguageMgr;
import com.yanqu.road.server.manger.ServerListMgr;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.config.MallRechargeConfigMgr;
import com.yanqu.road.server.manger.log.AutoLogMgr;
import com.yanqu.road.server.manger.config.MallMgr;
import com.yanqu.road.server.manger.log.LogMgr;
import com.yanqu.road.server.manger.maidian.DefaultEventTraceAction;
import com.yanqu.road.server.manger.recharge.RechargeMgr;
import com.yanqu.road.server.manger.union.UnionActivityMgr;
import com.yanqu.road.server.pb.SubscribePb;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.webservice.GamePublicFunction;
import com.yanqu.road.utils.LocalDateTimeHelper;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;
import org.apache.commons.collections.map.HashedMap;

import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 用户充值模块
 */
public class RechargeModule extends GeneralModule {

    private static final Object rechargeLock = new Object();

    private List<RechargeOrder> rechargeOrderList;
    private List<ThirdPartyRechargeOrder> thirdPartyRechargeOrderList;
    private Map<String, RechargeOrder> changeRepeatMap = new ConcurrentHashMap<>();
    private Map<String, ThirdPartyRechargeOrder> changeThirdRepeatMap = new ConcurrentHashMap<>();
    private Map<Integer, UserSubscribe> userSubscribeMap;

    public RechargeModule(GamePlayer player) {
        super(player);
    }

    @Override
    public boolean saveData() {
        for(RechargeOrder data : changeRepeatMap.values()){
            if(RechargeBussiness.updateRechargeOrderRepeatBuy(data)) {
                changeRepeatMap.remove(data.getOrderNo());
            }
        }
        for(ThirdPartyRechargeOrder data : changeThirdRepeatMap.values()){
            if(RechargeBussiness.updateThirdPartyRechargeRepeatBuy(data)){
                changeThirdRepeatMap.remove(data.getPlatformOrderNo());
            }
        }
        for(UserSubscribe data : userSubscribeMap.values()){
            if(data.isInsertOption()){
                SubscribeBussiness.addUserSubscribe(data);
            }else if(data.isUpdateOption()){
                SubscribeBussiness.updateUserSubscribe(data);
            }
        }
        return true;
    }

    @Override
    public boolean afterLoadData() {
        return true;
    }

    @Override
    public boolean loadData() {
        List<RechargeOrder> tempList = RechargeBussiness.getAllRechargeOrderList(player.getUserId());
        //1个月前没付款的订单就不加载内存了 start
        if(!tempList.isEmpty()) {
            long selectTime = System.currentTimeMillis() - DateHelper.DAY_MILLIONS * 45;
            Iterator<RechargeOrder> iterator = tempList.iterator();
            while (iterator.hasNext()){
                RechargeOrder order = iterator.next();
                if(order.getOrderStatus() == eOrderStatus.PreOrder && order.getCreateTime().getTime() < selectTime){
                    iterator.remove();
                }
            }
        }
        rechargeOrderList = tempList;
        //1个月前没付款的订单就不加载内存了 end
        thirdPartyRechargeOrderList = RechargeBussiness.getThirdPartyRechargeOrderList(player.getUserId());
        userSubscribeMap = SubscribeBussiness.getUserSubscribeMap(player.getUserId());
        return true;
    }

    @Override
    public void afterLogin() {
        // 处理下周末系统充值
        player.notifyListener(eGamePlayerEventType.WeekendDayRecharge.getValue(), player.getModule(AttributeModule.class).getAttribute(ePlayerAttrType.DayTotalRecharge));
        syncRechargeDetail();
        syncSubscribeList(new ArrayList<>(userSubscribeMap.values()), true);
    }

    public synchronized void loginLogic() {
        if (null != rechargeOrderList && rechargeOrderList.size() > 0) {
            for (RechargeOrder order : rechargeOrderList) {
                if (order.getOrderStatus() == eOrderStatus.ToBeCharged) {
                    rechargeSuccess(order, false);
                }
            }
        }
        if (null != thirdPartyRechargeOrderList && thirdPartyRechargeOrderList.size() > 0) {
            for (ThirdPartyRechargeOrder order : thirdPartyRechargeOrderList) {
                if (order.getOrderStatus() == eOrderStatus.ToBeCharged) {
                    thirdPartyRechargeSuccess(order, false);
                }
            }
        }
    }

    public void syncRechargeDetail(){
        long lastRechargeTime = player.getModule(AttributeModule.class).getAttribute(ePlayerAttrType.LastRechargeTime);
        RechargeProto.RechargeDetailMsg.Builder msg = RechargePb.parseRechargeDetailMsg(lastRechargeTime);
        player.sendPacket(Protocol.U_RECHARGE_DETAIL_SYNC, msg);
    }

    /**
     * 是否买过基金
     */
    public boolean hasBuyFund(int fundMallId){
        RechargeOrder rechargeOrder = RechargeManager.getHasBeChargeRechargeOrder(fundMallId, rechargeOrderList);
        if(null != rechargeOrder){
            return true;
        }
        ThirdPartyRechargeOrder thirdPartyRechargeOrder = RechargeManager.getHasBeChargeThirdPartyOrder(fundMallId, thirdPartyRechargeOrderList);
        if(null != thirdPartyRechargeOrder){
            return true;
        }
        return false;
    }

    /**
     * 充值到账，付款成功
     */
    public final int rechargeSuccess(RechargeOrder rechargeOrder, boolean isAddToList) {
        synchronized (rechargeLock) {
            //判断该笔订单是不是已经充值到账 如果已经充值到账 则不再发放
            for (RechargeOrder order : rechargeOrderList) {
                if (order.getOrderNo().equals(rechargeOrder.getOrderNo())) {
                    if(order.getOrderStatus().equals(eOrderStatus.HasBeenCharged)) {
                        log.error("订单产品id{}已经充值,playerId:{}", rechargeOrder.getOrderNo(), player.getUserId());
                        return GameErrorCode.E_RECHARGE_FAIL;
                    }else if(order.getOrderStatus().equals(eOrderStatus.ReturnIngots)){
                        log.error("订单产品id{}已经返元宝,playerId:{}", rechargeOrder.getOrderNo(), player.getUserId());
                        return GameErrorCode.E_RECHARGE_FAIL;
                    }
                }
            }
            log.info("订单正在充值{},player:{}", rechargeOrder.getOrderNo(), player.getUserId());
            rechargeOrder.setVipExp(player.getUserInfo().getVipExp());
            MallInfo mallInfo = MallMgr.getMallInfoByMallId(rechargeOrder.getMallId());
            if(null != mallInfo){
                int success;
                if(eOrderProductType.Subscription.getValue().equals(rechargeOrder.getProductType())){
                    success = dealSubscribeRechargeReward(rechargeOrder, mallInfo, isAddToList);
                }else {
                    success = dealMallRechargeReward(rechargeOrder, mallInfo, isAddToList);
                }
                if(success == 0){
                    //订单完成
                    DataAnalyticsMgr.trackOrderFinish(rechargeOrder, mallInfo);
                    player.getModule(ActivityMallModule.class).extendOperation(mallInfo);
                }
                return success;
            }else {
                int success = dealMallNoFindReturnGoldToken(rechargeOrder, isAddToList);
                if(success == 0){
                    //订单完成
                    DataAnalyticsMgr.trackOrderFinish(rechargeOrder, null);
                }
                return success;
            }
        }
    }

    private int dealMallRechargeReward(RechargeOrder rechargeOrder, MallInfo mallInfo, boolean isAddToList){
        long money = 0;
        if(null != mallInfo){
            money = MallRechargeConfigMgr.getPrice(mallInfo);
//            money = Long.parseLong(mallInfo.getPrice());
        }
        if (null == mallInfo || 0 == money) {
            log.error("订单产品id未找到{},订单号{},playerId:{}", rechargeOrder.getMallId(), rechargeOrder.getOrderNo(),
                    player.getUserId());
            return GameErrorCode.E_MALL_NO_EXIST;
        }
        rechargeOrder.setOrderStatus(eOrderStatus.HasBeenCharged);
        if (RechargeBussiness.updateRechargeOrderStatus(rechargeOrder)) {
            if(rechargeOrder.getPayType() == 3){//ios钱包的，返利10%元宝
                Property ingotsReward = new Property(GameConfig.GAME_MONEY_INGOTS, BigInteger.valueOf(money / 100));
                player.getModule(CurrencyModule.class).addCurrency(ingotsReward, eLogMoneyType.Recharge, eLogMoneyType.ReChargeGet);
            }
            boolean isRepeatBuy;
            ActivityInfo activityInfo = null;
            if(rechargeOrder.getActivityId() > 0){
                activityInfo = ActivityMgr.getOpenActivityInfo(rechargeOrder.getActivityId());
            }
            String actType = ActivityMgr.getActType(mallInfo, activityInfo);
            BaseRecharge baseRecharge = BaseRecharge.getBaseChargeLogic(player, mallInfo, activityInfo);
            if(null == baseRecharge){
                isRepeatBuy = true;
                MallMgr.returnGoldToken(player, mallInfo, rechargeOrder.getCouponGoodsId());
                log.error("getBaseChargeLogic null,orderNo:{},mallId:{},activityId:{},playerId:{}", rechargeOrder.getOrderNo(),
                        rechargeOrder.getMallId(), rechargeOrder.getActivityId(), player.getUserId());
            }else {
                RechargeResult rechargeResult = baseRecharge.recharge(rechargeOrder.getOrderNo(), rechargeOrderList, thirdPartyRechargeOrderList,
                        false, true, rechargeOrder);
                isRepeatBuy = rechargeResult.isRepeatedBuy();
            }
            if(!isRepeatBuy) {
                player.getModule(ActivityMallModule.class).addMallBuyCount(mallInfo, 1);
            }
            //通知客户端到账
            notifyClientRechargeSuccess(rechargeOrder.getMallId(), isRepeatBuy, rechargeOrder);

            player.notifyListener(eGamePlayerEventType.RechargePotentialAnd.getValue(), new PotentialArg(false, 0));
            player.notifyListener(eGamePlayerEventType.RechargePotentialOr.getValue(), new PotentialArg(false, 0));
            LogMgr.addLogRecharge(player.getUserId(), mallInfo.getMallId(), 1, rechargeOrder.getAmount(), rechargeOrder.getPlatformOrderNo(),
                GameServer.getInstance().getServerId(), 0, rechargeOrder.getSdkOrderNo(), player.getUserInfo().getVipExp(), actType,
                rechargeOrder.getCurrency(), rechargeOrder.getRealMoney(), rechargeOrder.getRealCurrency(), rechargeOrder.getLocalMoney(),
                rechargeOrder.getLocalCurrency(), rechargeOrder.getLtrRate(), rechargeOrder.getNewMoney(), rechargeOrder.getTax(),
                rechargeOrder.getProductCoin(), rechargeOrder.getDevice(), rechargeOrder.getPayChannel(), rechargeOrder.getPlatformOrderNo(),
                rechargeOrder.getActivityId(), rechargeOrder.getCouponMoney(), rechargeOrder.getMallMarkId(), isRepeatBuy);

            //设置一下重复购买状态
            rechargeOrder.setRepeatBuy(isRepeatBuy);
            if(!changeRepeatMap.containsKey(rechargeOrder.getOrderNo())) {
                changeRepeatMap.put(rechargeOrder.getOrderNo(), rechargeOrder);
            }

            //添加到充值列表中
            if (isAddToList) {
                rechargeOrderList.add(rechargeOrder);
            }
            return 0;
        }
        return GameErrorCode.E_RECHARGE_FAIL;
    }

    private int dealSubscribeRechargeReward(RechargeOrder rechargeOrder, MallInfo mallInfo, boolean isAddToList){
        long money = 0;
        if(null != mallInfo){
            money = MallRechargeConfigMgr.getPrice(mallInfo);
//            money = Long.parseLong(mallInfo.getPrice());
        }
        if (null == mallInfo || 0 == money) {
            log.error("订单产品id未找到{},订单号{},playerId:{}", rechargeOrder.getMallId(), rechargeOrder.getOrderNo(),
                    player.getUserId());
            return GameErrorCode.E_MALL_NO_EXIST;
        }
        rechargeOrder.setOrderStatus(eOrderStatus.HasBeenCharged);
        if (RechargeBussiness.updateRechargeOrderStatus(rechargeOrder)) {
            boolean isRepeatBuy;
            ActivityInfo activityInfo = null;
            String actType = ActivityMgr.getActType(mallInfo, activityInfo);
            BaseRecharge baseRecharge = BaseRecharge.getBaseChargeLogic(player, mallInfo, activityInfo);
            if(null == baseRecharge){
                isRepeatBuy = true;
                MallMgr.returnGoldToken(player, mallInfo, rechargeOrder.getCouponGoodsId());
                log.error("getBaseChargeLogic null,orderNo:{},mallId:{},activityId:{},playerId:{}", rechargeOrder.getOrderNo(),
                        rechargeOrder.getMallId(), rechargeOrder.getActivityId(), player.getUserId());
            }else {
                RechargeResult rechargeResult = baseRecharge.recharge(rechargeOrder.getOrderNo(), rechargeOrderList, thirdPartyRechargeOrderList,
                        false, true, rechargeOrder);
                isRepeatBuy = rechargeResult.isRepeatedBuy();
            }
            if(!isRepeatBuy) {
                player.getModule(ActivityMallModule.class).addMallBuyCount(mallInfo, 1);
            }
            //通知客户端到账
            notifyClientRechargeSuccess(rechargeOrder.getMallId(), isRepeatBuy, rechargeOrder);

            player.notifyListener(eGamePlayerEventType.RechargePotentialAnd.getValue(), new PotentialArg(false, 0));
            player.notifyListener(eGamePlayerEventType.RechargePotentialOr.getValue(), new PotentialArg(false, 0));
            LogMgr.addLogRecharge(player.getUserId(), mallInfo.getMallId(), 1, rechargeOrder.getAmount(), rechargeOrder.getPlatformOrderNo(),
                    GameServer.getInstance().getServerId(), 0, rechargeOrder.getSdkOrderNo(), player.getUserInfo().getVipExp(), actType,
                    rechargeOrder.getCurrency(), rechargeOrder.getRealMoney(), rechargeOrder.getRealCurrency(), rechargeOrder.getLocalMoney(),
                    rechargeOrder.getLocalCurrency(), rechargeOrder.getLtrRate(), rechargeOrder.getNewMoney(), rechargeOrder.getTax(),
                    rechargeOrder.getProductCoin(), rechargeOrder.getDevice(), rechargeOrder.getPayChannel(), rechargeOrder.getPlatformOrderNo(),
                    rechargeOrder.getActivityId(), rechargeOrder.getCouponMoney(), rechargeOrder.getMallMarkId(), isRepeatBuy);

            //设置一下重复购买状态
            rechargeOrder.setRepeatBuy(isRepeatBuy);
            if(!changeRepeatMap.containsKey(rechargeOrder.getOrderNo())) {
                changeRepeatMap.put(rechargeOrder.getOrderNo(), rechargeOrder);
            }

            //添加到充值列表中
            if (isAddToList) {
                rechargeOrderList.add(rechargeOrder);
            }
            return 0;
        }
        return GameErrorCode.E_RECHARGE_FAIL;
    }

    public void notifyClientRechargeSuccess(int mallId, boolean isRepeatBuy,RechargeOrder rechargeOrder){
        RechargeProto.RechargeNotifyClientSuccessMsg.Builder msg = RechargeProto.RechargeNotifyClientSuccessMsg.newBuilder();
        msg.setMallId(mallId);
        msg.setIsRepeatBuy(isRepeatBuy);
        if (!StringUtils.isNullOrEmpty(rechargeOrder.getOrderNo())) {
            msg.setOrderNo(rechargeOrder.getOrderNo());
        }
        if (!StringUtils.isNullOrEmpty(rechargeOrder.getPlatformOrderNo())) {
            msg.setPlatformOrderNo(rechargeOrder.getPlatformOrderNo());
        }

        player.sendPacket(Protocol.U_RECHARGE_NOTIFY_CLIENT_SUCCESS, msg);
    }

    /**
     * 充值到账，付款成功
     */
    public final int thirdPartyRechargeSuccess(ThirdPartyRechargeOrder thirdPartyRechargeOrder, boolean isAddToList) {
        synchronized (rechargeLock) {
            //判断该笔订单是不是已经充值到账 如果已经充值到账 则不再发放
            for (ThirdPartyRechargeOrder order : thirdPartyRechargeOrderList) {
                if (order.getPlatformOrderNo().equals(thirdPartyRechargeOrder.getPlatformOrderNo()) && order.getOrderStatus().equals(eOrderStatus.HasBeenCharged)) {
                    log.error("thirdPartyRecharge orderNo:{}已经充值,playerId:{}", thirdPartyRechargeOrder.getPlatformOrderNo(),
                            player.getUserId());
                    return GameErrorCode.E_RECHARGE_FAIL;
                }
            }
            log.info("thirdPartyRecharge orderNo:{}正在充值,playerId:{}", thirdPartyRechargeOrder.getPlatformOrderNo(),
                    player.getUserId());
            thirdPartyRechargeOrder.setOrderStatus(eOrderStatus.HasBeenCharged);
            thirdPartyRechargeOrder.setVipExp(player.getUserInfo().getVipExp());
            thirdPartyRechargeOrder.setUpdateTime(new Date());
            int channelId = ServerListMgr.getChannelId(GameServer.getInstance().getServerId());
            if(eChannelType.isTwChannel(channelId)){
                int success = thirdPartySuccessDealTw(thirdPartyRechargeOrder, isAddToList);
                if(success == 0){
                    //订单完成
                    DataAnalyticsMgr.trackOrderFinish(thirdPartyRechargeOrder);
                }
                return success;
            }else {
                int success = thirdPartySuccessDealOther(thirdPartyRechargeOrder, isAddToList);
                if(success == 0){
                    //订单完成
                    DataAnalyticsMgr.trackOrderFinish(thirdPartyRechargeOrder);
                }
                return success;
            }
        }
    }

    /**
     * 充值到账，付款成功
     */
    private int thirdPartySuccessDealOther(ThirdPartyRechargeOrder thirdPartyRechargeOrder, boolean isAddToList) {
        MallInfo mallInfo = null;
        if(thirdPartyRechargeOrder.getMallId() > 0) {
            mallInfo = MallMgr.getMallInfoByMallId(thirdPartyRechargeOrder.getMallId());
            if (null == mallInfo) {
                log.error("thirdPartySuccessDealOther mall:{} no find,orderNo:{},playerId:{}", thirdPartyRechargeOrder.getMallId(),
                        thirdPartyRechargeOrder.getPlatformOrderNo(), player.getUserId());
                return GameErrorCode.E_MALL_NO_EXIST;
            }
            long money = MallRechargeConfigMgr.getPrice(mallInfo);
//            long money = Long.parseLong(mallInfo.getPrice());
            if (money <= 0) {
                log.error("thirdPartySuccessDealOther money:{} error,orderNo:{},mallId:{},playerId:{}", money,
                        thirdPartyRechargeOrder.getPlatformOrderNo(), thirdPartyRechargeOrder.getMallId(), player.getUserId());
                return GameErrorCode.E_RECHARGE_FAIL;
            }
        }

        if (RechargeBussiness.updateThirdPartyRechargeOrder(thirdPartyRechargeOrder)) {
            if(thirdPartyRechargeOrder.getMallId() > 0) {
                dealMall(thirdPartyRechargeOrder, mallInfo);
            }
            if(thirdPartyRechargeOrder.getIngots() > 0){
                //处理到账
                this.dealIngots(thirdPartyRechargeOrder);
            }
            //添加到充值列表中
            if (isAddToList) {
                thirdPartyRechargeOrderList.add(thirdPartyRechargeOrder);
            }
            return 0;
        }
        return GameErrorCode.E_RECHARGE_FAIL;
    }

    /**
     * 处理通宝，元宝到账
     * @param thirdPartyRechargeOrder
     */
    private void dealIngots(ThirdPartyRechargeOrder thirdPartyRechargeOrder) {
        if(Objects.equals(thirdPartyRechargeOrder.getPayChannel(), "direct_pay") ||
                Objects.equals(thirdPartyRechargeOrder.getPayChannel(), "virtual_account") ||
                Objects.equals(thirdPartyRechargeOrder.getPayChannel(), "direct_pay_hk") ||
                (Objects.equals(thirdPartyRechargeOrder.getPayChannel(), "direct_pay_awx"))
        ) {
            //以上的渠道通过邮件发
            sendGoldToken(thirdPartyRechargeOrder);
        } else {
            //直接发玩家背包
            log.info("dealIngots orderNo:{},充值元宝:{},playerId:{}", thirdPartyRechargeOrder.getPlatformOrderNo(), thirdPartyRechargeOrder.getIngots(), player.getUserId());
            long ingots = 0;
            long addVip = 0;
            long token = 0;
            if (thirdPartyRechargeOrder.getSubCoinType() == 0) {
                ingots += thirdPartyRechargeOrder.getRealIngots();
                // 只有充这个元宝才会加vip经验
                addVip = thirdPartyRechargeOrder.getRealIngots() / 10;
            } else {
                token += thirdPartyRechargeOrder.getRealIngots();
            }
            if (thirdPartyRechargeOrder.getExtraCoinType() == 0) {
                ingots += thirdPartyRechargeOrder.getExtraIngots();
            } else {
                token += thirdPartyRechargeOrder.getExtraIngots();
            }
            Property reward = new Property();
            if (ingots > 0) {
                reward.addProperty(new Property(GameConfig.GAME_MONEY_INGOTS, BigInteger.valueOf(ingots)));
            }
            if (token > 0) {
                reward.addProperty(new Property(eItemId.GOLD_TOKEN.getValue(), BigInteger.valueOf(token)));
            }
            dealIngotsReward(thirdPartyRechargeOrder, addVip, reward);
        }
    }

    /**
     * 处理商品到账
     * @param thirdPartyRechargeOrder
     * @param mallInfo
     */
    private void dealMall(ThirdPartyRechargeOrder thirdPartyRechargeOrder, MallInfo mallInfo) {
        ActivityInfo activityInfo = null;
        if (mallInfo.getCategory() == eMallCategory.RechargeGoods.getValue()) {
            FindActivityResult findResult = GamePublicFunction.findActivityMall(thirdPartyRechargeOrder.getMallId());
            if(findResult.isFind()){
                activityInfo = ActivityMgr.getOpenActivityInfo(findResult.getActivityId());
            }
        } else {
            activityInfo = ActivityMgr.getOpenActivityInfo(mallInfo.getActivityId());
        }
        BaseRecharge baseRecharge;
        int channelId = ServerListMgr.getChannelId(GameServer.getInstance().getServerId());
        if (mallInfo.getCategory() == eMallCategory.Ingots.getValue() &&
            (eChannelType.isKrChannel(channelId) || eChannelType.isThinChannel(channelId) ||
            eChannelType.isUkChannel(channelId) || eChannelType.isUkChannel(channelId) ||
            eChannelType.isVnChannel(channelId) || eChannelType.isJapanChannel(channelId))
        ){//韩国、越南、国际服第三方首充翻倍
            baseRecharge = new IngotsRechargeThirdDouble(player, mallInfo, activityInfo);
        } else{
            baseRecharge = BaseRecharge.getBaseChargeLogic(player, mallInfo, activityInfo);
        }
        int activityId = 0;
        if(null != activityInfo){
            activityId = activityInfo.getActivityId();
        }
        String actType = ActivityMgr.getActType(mallInfo, activityInfo);
        boolean isRepeatBuy;
        if(null == baseRecharge){
            isRepeatBuy = true;
            MallMgr.returnGoldToken(player, mallInfo, 0);
            log.error("getBaseChargeLogic null,orderNo:{},mallId:{},activityId:{},playerId:{}", thirdPartyRechargeOrder.getPlatformOrderNo(),
                    thirdPartyRechargeOrder.getMallId(), activityId, player.getUserId());
        }else {
            RechargeResult rechargeResult = baseRecharge.recharge(thirdPartyRechargeOrder.getPlatformOrderNo(), rechargeOrderList, thirdPartyRechargeOrderList,
                    true, true, null);
            isRepeatBuy = rechargeResult.isRepeatedBuy();
        }
        if(!isRepeatBuy) {
            player.getModule(ActivityMallModule.class).addMallBuyCount(mallInfo, 1);
        }

        //设置重复购买
        thirdPartyRechargeOrder.setRepeatBuy(isRepeatBuy);
        if(!changeThirdRepeatMap.containsKey(thirdPartyRechargeOrder.getPlatformOrderNo())){
            changeThirdRepeatMap.put(thirdPartyRechargeOrder.getPlatformOrderNo(), thirdPartyRechargeOrder);
        }

        LogMgr.addLogRecharge(player.getUserId(), mallInfo.getMallId(), 1, thirdPartyRechargeOrder.getAmount(), thirdPartyRechargeOrder.getPlatformOrderNo(),
                GameServer.getInstance().getServerId(), 1, thirdPartyRechargeOrder.getSdkOrderNo(), player.getUserInfo().getVipExp(), actType,
                thirdPartyRechargeOrder.getCurrency(), thirdPartyRechargeOrder.getRealMoney(), thirdPartyRechargeOrder.getRealCurrency(),
                thirdPartyRechargeOrder.getLocalMoney(), thirdPartyRechargeOrder.getLocalCurrency(), thirdPartyRechargeOrder.getLtrRate(),
                thirdPartyRechargeOrder.getNewMoney(), thirdPartyRechargeOrder.getTax(), thirdPartyRechargeOrder.getProductCoin(),
                thirdPartyRechargeOrder.getDevice(), thirdPartyRechargeOrder.getPayChannel(), thirdPartyRechargeOrder.getPlatformOrderNo(),
                thirdPartyRechargeOrder.getActivityId(), thirdPartyRechargeOrder.getCouponMoney(), mallInfo.getMallMarkId(), isRepeatBuy);
    }

    private void dealIngotsReward(ThirdPartyRechargeOrder thirdPartyRechargeOrder, long addVip, Property reward){
        player.getModule(CurrencyModule.class).addCurrency(reward, eLogMoneyType.Recharge, eLogMoneyType.ReChargeGet);
        long originalValue = player.getUserInfo().getVipExp();
        addVipExp(addVip);
        LogMgr.addLogRecharge(player.getUserId(), 0, 1, thirdPartyRechargeOrder.getAmount(), thirdPartyRechargeOrder.getPlatformOrderNo(),
                GameServer.getInstance().getServerId(), 1, thirdPartyRechargeOrder.getSdkOrderNo(), player.getUserInfo().getVipExp(), "",
                thirdPartyRechargeOrder.getCurrency(), thirdPartyRechargeOrder.getRealMoney(), thirdPartyRechargeOrder.getRealCurrency(),
                thirdPartyRechargeOrder.getLocalMoney(), thirdPartyRechargeOrder.getLocalCurrency(), thirdPartyRechargeOrder.getLtrRate(),
                thirdPartyRechargeOrder.getNewMoney(), thirdPartyRechargeOrder.getTax(), thirdPartyRechargeOrder.getProductCoin(),
                thirdPartyRechargeOrder.getDevice(), thirdPartyRechargeOrder.getPayChannel(), thirdPartyRechargeOrder.getPlatformOrderNo(),
                thirdPartyRechargeOrder.getActivityId(), thirdPartyRechargeOrder.getCouponMoney(), 0, false);
        AutoLogMgr.add(new LogVipExp(player.getUserId(), originalValue, addVip, originalValue + addVip, 0, "第三方元宝充值"));//第三方元宝充值
    }

    /**
     * 充值到账，付款成功
     */
    private int thirdPartySuccessDealTw(ThirdPartyRechargeOrder thirdPartyRechargeOrder, boolean isAddToList) {
        if(!Objects.equals(eOrderProductType.Coin.getValue(), thirdPartyRechargeOrder.getProductType()) &&
                !Objects.equals(eOrderProductType.Package.getValue(), thirdPartyRechargeOrder.getProductType())){
            log.error("thirdPartySuccessDealTw product type unknown,orderNo:{},product type:{},playerId:{}",
                    thirdPartyRechargeOrder.getPlatformOrderNo(), thirdPartyRechargeOrder.getProductType(), player.getUserId());
            return GameErrorCode.E_RECHARGE_FAIL;
        }
        if(Objects.equals(eOrderProductType.Coin.getValue(), thirdPartyRechargeOrder.getProductType())){
            return thirdPartyRechargeIngots(thirdPartyRechargeOrder, isAddToList);
        }else {
            return thirdPartyRechargeMall(thirdPartyRechargeOrder, isAddToList);
        }
    }

    public int backendRechargeMall(int productId){
        MallInfo mallInfo = MallMgr.getMallInfoByMallId(productId);
        if (null == mallInfo) {
            log.error("backendRechargeMall mall not found : productId:{}",productId);
            return GameErrorCode.E_MALL_NO_EXIST;
        }
        ActivityInfo activityInfo = null;
        if (mallInfo.getCategory() == eMallCategory.RechargeGoods.getValue()) {
            FindActivityResult findResult = GamePublicFunction.findActivityMall(productId);
            if(findResult.isFind()){
                activityInfo = ActivityMgr.getOpenActivityInfo(findResult.getActivityId());
            }
        } else {
            activityInfo = ActivityMgr.getOpenActivityInfo(mallInfo.getActivityId());
        }
        int activityId = 0;
        if(null != activityInfo){
            activityId = activityInfo.getActivityId();
        }

        BaseRMBMallLimit baseRMBMallLimit = MallLimitFactory.getMallLimit(player.getUserId(), mallInfo, activityInfo);
        if(null == baseRMBMallLimit){
            MallMgr.returnGoldToken(player, mallInfo, 0);
            return 0;
        }
        if(0 != baseRMBMallLimit.checkMallLimit().getRet()){
            MallMgr.returnGoldToken(player, mallInfo, 0);
            return 0;
        }

        BaseRecharge baseRecharge = BaseRecharge.getBaseChargeLogic(player, mallInfo, activityInfo);
        if(null == baseRecharge) {
            MallMgr.returnGoldToken(player, mallInfo, 0);
        }else {
            baseRecharge.backendRecharge();
            //添加宴会帖
            player.getModule(BanquetModule.class).getCrossBanquetInvitationReward(mallInfo.getReward(),activityId);
            addRechargeAmount(mallInfo);
        }
        player.getModule(ActivityMallModule.class).addMallBuyCount(mallInfo, 1);

        try {
            DefaultEventTraceAction traceAction = new DefaultEventTraceAction("cz_finish", player);
            long price = MallRechargeConfigMgr.getPrice(mallInfo);
            traceAction.build("reason_id", productId).build("reason_amount", price).trace();
        }catch (Exception e){
            DataAnalyticsMgr.getLogger().error("", e);
        }
        return 0;
    }

    private int thirdPartyRechargeMall(ThirdPartyRechargeOrder thirdPartyRechargeOrder, boolean isAddToList) {
        MallInfo mallInfo = MallMgr.getMallInfoByMallId(thirdPartyRechargeOrder.getMallId());
        if (null == mallInfo) {
            log.error("thirdPartyRecharge mall:{} no find,orderNo:{},playerId:{}", thirdPartyRechargeOrder.getMallId(),
                    thirdPartyRechargeOrder.getPlatformOrderNo(), player.getUserId());
            return GameErrorCode.E_MALL_NO_EXIST;
        }
        long money = MallRechargeConfigMgr.getPrice(mallInfo);
//        long money = Long.parseLong(mallInfo.getPrice());
        if (money <= 0) {
            log.error("thirdPartyRecharge money:{} error,orderNo:{},mallId:{},playerId:{}", money, thirdPartyRechargeOrder.getPlatformOrderNo(),
                    thirdPartyRechargeOrder.getMallId(), player.getUserId());
            return GameErrorCode.E_RECHARGE_FAIL;
        }

        if (RechargeBussiness.updateThirdPartyRechargeOrder(thirdPartyRechargeOrder)) {
            dealMall(thirdPartyRechargeOrder, mallInfo);

            //添加到充值列表中
            if (isAddToList) {
                thirdPartyRechargeOrderList.add(thirdPartyRechargeOrder);
                player.getModule(ZhanLingActivityModule.class).syncActivity();
            }
            return 0;
        }
        return GameErrorCode.E_RECHARGE_FAIL;
    }

    private int thirdPartyRechargeIngots(ThirdPartyRechargeOrder thirdPartyRechargeOrder, boolean isAddToList) {
        long money = thirdPartyRechargeOrder.getAmount();
        if (money <= 0) {
            log.error("thirdPartyRecharge money:{} error,orderNo:{},playerId:{}", money, thirdPartyRechargeOrder.getPlatformOrderNo(),
                    player.getUserId());
            return GameErrorCode.E_RECHARGE_FAIL;
        }
        long ingots = 0;
        // 通宝数
        long token = 0;
        if (thirdPartyRechargeOrder.getRealIngots() <= 0 && thirdPartyRechargeOrder.getExtraIngots() <= 0 && thirdPartyRechargeOrder.getMallId() == 0) {
            log.error("thirdPartyRecharge ingots:{} error,orderNo:{},playerId:{}", money, thirdPartyRechargeOrder.getPlatformOrderNo(),
                    player.getUserId());
            return GameErrorCode.E_RECHARGE_FAIL;
        }
        if (RechargeBussiness.updateThirdPartyRechargeOrder(thirdPartyRechargeOrder)) {
            long addVip = 0;
            Property reward = new Property();
            if(thirdPartyRechargeOrder.getMallId() == 0){//充值任意元宝
                //处理通宝，元宝到账
                this.dealIngots(thirdPartyRechargeOrder);
            }else {//充值游戏内配置元宝
                MallInfo mallInfo = MallMgr.getMallInfoByMallId(thirdPartyRechargeOrder.getMallId());
                if(null == mallInfo){
                    log.error("thirdPartyRecharge mall no find,orderNo:{},mallId:{},playerId:{}", thirdPartyRechargeOrder.getPlatformOrderNo(),
                            thirdPartyRechargeOrder.getMallId(), player.getUserId());
                    return GameErrorCode.E_RECHARGE_FAIL;
                }
                if(mallInfo.getCategory() != eMallCategory.Ingots.getValue()){
                    log.error("thirdPartyRecharge mall category error,orderNo:{},mallId:{},playerId:{}", thirdPartyRechargeOrder.getPlatformOrderNo(),
                            thirdPartyRechargeOrder.getMallId(), player.getUserId());
                    return GameErrorCode.E_RECHARGE_FAIL;
                }
                ingots = GamePublicFunction.twGetIngotMallIngotCount(mallInfo);
                reward = new Property(GameConfig.GAME_MONEY_INGOTS, BigInteger.valueOf(ingots));
                //判断首充翻倍
                if (player.getModule(RechargeGainModule.class).isFirstRechargeDouble(mallInfo, eRechargeGainIndex.ThirdPartyFirstDouble.getValue())) {
                    Property ingotsReward = new Property(GameConfig.GAME_MONEY_INGOTS, BigInteger.valueOf(ingots));
                    reward.addProperty(ingotsReward);
                    //设置翻倍标识
                    if(RechargeMgr.isUseNewMultiple()) {
                        player.getModule(RechargeGainModule.class).changeRechargeTimes(mallInfo.getMallId(), eRechargeGainIndex.ThirdPartyFirstDouble.getValue());
                    }else {
                        player.getModule(RechargeGainModule.class).changeRechargeGain(mallInfo.getMallId(), eRechargeGainIndex.ThirdPartyFirstDouble.getValue());
                    }
                    LogMgr.addLogThirdRechargeDouble(player.getUserId(), thirdPartyRechargeOrder.getPlatformOrderNo(), thirdPartyRechargeOrder.getSdkOrderNo(),
                            mallInfo.getMallId(), PropertyHelper.parsePropertyToString(ingotsReward));
                }
                if (ingots % 10 != 0) {
                    addVip = ingots / 10 + 1;
                } else {
                    addVip = ingots / 10;
                }
                log.info("thirdPartyRecharge orderNo:{},mallId:{},元宝数量:{}", thirdPartyRechargeOrder.getPlatformOrderNo(),
                        thirdPartyRechargeOrder.getMallId(), ingots);
                dealIngotsReward(thirdPartyRechargeOrder, addVip, reward);
            }

            //添加到充值列表中
            if (isAddToList) {
                thirdPartyRechargeOrderList.add(thirdPartyRechargeOrder);
                player.getModule(ZhanLingActivityModule.class).syncActivity();
            }
            return 0;
        }
        return GameErrorCode.E_RECHARGE_FAIL;
    }

    /**
     * 增加充值额度
     */
    public void addRechargeAmount(MallInfo mallInfo) {
        if(null != mallInfo){
            long originalValue = player.getUserInfo().getVipExp();
            //获取vip经验
            int vipExp = (int) MallRechargeConfigMgr.getParamValue(mallInfo);
//            int vipExp = StringUtils.string2intSafe(mallInfo.getParam(), 0);

            //只有老玩家便宜购买月卡的时候需要做判断!!
            if (mallInfo.getCategory() == eMallCategory.ReturnRoleOnlyPrivilegeCard.getValue()){
                if (mallInfo.getShopType() == 19){//月卡的shoptype
                    MallInfo mallInfoByMallId = MallMgr.getMallInfoByMallId(GameConfig.WEEK_CARD_MALL_ID);
                    if (mallInfoByMallId != null){
                        vipExp = (int) MallRechargeConfigMgr.getParamValue(mallInfoByMallId);
//                        vipExp = StringUtils.string2intSafe(mallInfoByMallId.getParam(), 0);
                    }
                }
            }

            // 2022年12月7日11:40:14热更：瓦舍夺魁战令要加充值活动 zkt todo 后续需要优化下这段代码
            if (mallInfo.getShopType() == eShopType.ChineseChessSilverToken.getValue() || mallInfo.getShopType() == eShopType.ChineseChessGoldToken.getValue()) {
                // 用通用战令类型的需要计入日充的需要在这里加商品分类，没加的话默认不算日充
                if (mallInfo.getCategory() == eMallCategory.WasheToken.getValue()
                        || mallInfo.getCategory() == eMallCategory.SnowGardenToken.getValue()
                        || mallInfo.getCategory() == eMallCategory.SummerGamesFound.getValue()
                        || mallInfo.getCategory() == eMallCategory.HsIslandZl.getValue()
                        || mallInfo.getCategory() == eMallCategory.ApprenticeFund.getValue()
                        || mallInfo.getCategory() == eMallCategory.GoldIngotFund.getValue()) {
                    addVipExp(vipExp); // 直接调用有加充值活动的方法
                    AutoLogMgr.add(new LogVipExp(player.getUserId(), originalValue, vipExp, originalValue + vipExp, mallInfo.getMallId(), mallInfo.getMallName()));
                    return;
                }
            }

            addVipExp(vipExp, mallInfo.getShopType());
            AutoLogMgr.add(new LogVipExp(player.getUserId(), originalValue, vipExp,originalValue + vipExp, mallInfo.getMallId(), mallInfo.getMallName()));
        }
    }

    //特殊的充值不加入活动中（特惠礼包中的购买项不享受充值活动，即不计入充值活动数据中。）
    public void addVipExp(int vipExp,int shopType){
        if(!activityNeedAddVipExp(shopType)){
            player.getModule(PlayerModule.class).addVipExp(vipExp);
        }else{
            addVipExp(vipExp);
        }
    }

    /**
     * 特惠礼包、跨服冲榜现金商店、花石纲现金商店不参与充值活动
     * @param shopType
     * @return
     */
    public boolean activityNeedAddVipExp(int shopType){
        return shopType != eShopType.SpecialMall.getValue() &&
                shopType != eShopType.CrossRankActivityRMBMall.getValue() &&
                shopType != eShopType.HuaShiGangMoneyMall.getValue() &&
                shopType != eShopType.DaFuWengMoneyMall.getValue() &&
                shopType != eShopType.UnionWarActivityRMBMall.getValue() &&
                shopType != eShopType.ZhanLingGiftShop.getValue() &&
                shopType != eShopType.DunHuangShiKuMoneyMall.getValue() &&
                shopType != eShopType.DouLuoDaLuActivityMoneyMall.getValue() &&
                shopType != eShopType.ChannelRankActivityRMBMall.getValue() &&
                shopType != eShopType.ChineseChessGoldToken.getValue() &&
                shopType != eShopType.ChineseChessSilverToken.getValue() &&
                shopType != eShopType.TongBingRmbMall.getValue() &&
                shopType != eShopType.ChuHanRmbMall.getValue() &&
                shopType != eShopType.TonBingRmbMall.getValue() &&
                shopType != eShopType.RankUnionWarRmbMall.getValue() &&
                shopType != eShopType.WasheRmbMall.getValue() &&
                shopType != eShopType.CricketNormalMall.getValue() &&
                shopType != eShopType.CricketAdvanceMall.getValue() &&
                shopType != eShopType.FiveHeroMoneyMall.getValue() &&
                shopType != eShopType.WaSheDirectPurchaseRmbMall.getValue() &&
                shopType != eShopType.JiuZhouRmbMall.getValue() &&
                shopType != eShopType.DoubleSpringHelp.getValue() &&
                shopType != eShopType.SuiTangTeHuiXJMall.getValue() &&
                shopType != eShopType.XingYouShanShuiRmbMall.getValue() &&
                shopType != eShopType.SonHaiGift.getValue()
                ;
    }

    public void addVipExp(long vipExp){
        if(vipExp > 0) {
            player.getModule(PlayerModule.class).addVipExp(vipExp);
            AttributeModule attributeModule = player.getModule(AttributeModule.class);
            //增加累充金额
            attributeModule.addAttribute(ePlayerAttrType.TotalRecharge, vipExp);
            //记录日充值
            attributeModule.addAttribute(ePlayerAttrType.DayTotalRecharge, vipExp);
            player.notifyListener(eGamePlayerEventType.Recharge.getValue(), vipExp);
            //周末系统充值
            player.notifyListener(eGamePlayerEventType.WeekendDayRecharge.getValue(), attributeModule.getAttribute(ePlayerAttrType.DayTotalRecharge));
            //商会充值
            notifyUnionActivity(vipExp);
            //记录充值天数
            long zeroTime = LocalDateTimeHelper.getZeroTimeTimeStamp() / 1000;
            long lastRechargeTime = attributeModule.getAttribute(ePlayerAttrType.LastRechargeTime);
            if (attributeModule.getAttribute(ePlayerAttrType.LastRechargeTime) < zeroTime) {
                //累计充值天数
                player.notifyListener(eGamePlayerEventType.RechargeDays.getValue(), new RechargeDaysArgs(1, false));
            }

            //记录首次充值时间
            long firstRechargeTime = attributeModule.getAttribute(ePlayerAttrType.FirstRechargeTime);
            if(firstRechargeTime <= 0){
                attributeModule.setAttribute(ePlayerAttrType.FirstRechargeTime, System.currentTimeMillis() / 1000);
            }

            //记录充值次数
            attributeModule.addAttribute(ePlayerAttrType.RechargeTotalTimes, 1);
            player.notifyListener(eGamePlayerEventType.RechargeTotalTimes.getValue(), attributeModule.getAttribute(ePlayerAttrType.RechargeTotalTimes));
            // 设置上一次充值时间
            player.getModule(AttributeModule.class).setAttribute(ePlayerAttrType.LastRechargeTime, System.currentTimeMillis() / 1000);
            //同步最近充值时间给客户端
            syncRechargeDetail();
            //首次充值时间
            DataAnalyticsMgr.firstPayTime(player, lastRechargeTime);

            int passId = 0;
            UserPassRoad userPassRoad = player.getModule(PassRoadModule.class).getUserPassRoad();
            if(null != userPassRoad){
                passId = userPassRoad.getPassId();
            }
            AutoLogMgr.add(new LogUserRechargeTimes(player.getUserId(), attributeModule.getAttribute(ePlayerAttrType.RechargeTotalTimes),
                    attributeModule.getAttribute(ePlayerAttrType.UserTotalOnlineTime), player.getTitleId(), passId));

        }
    }


    /**
     * 获取最近充值的金额（包含第三方、包含返还元宝）
     * 注 : 这个方法没线上跑过，用的时候记得再看看
     *
     * @return 结果乘100了
     */
    public long getRecentRechargeAccount(long time) {

        long beginTime = System.currentTimeMillis() - time;
        long account = 0L;

        Set<eOrderStatus> statusSet = new HashSet<>();
        statusSet.add(eOrderStatus.HasBeenCharged);
        statusSet.add(eOrderStatus.ReturnIngots);

        for (int i = 0; i < rechargeOrderList.size(); i++) {
            RechargeOrder order = rechargeOrderList.get(i);
            if (order.getCreateTime().getTime() > beginTime && statusSet.contains(order.getOrderStatus())) {
                account += order.getAmount();
            }
        }

        for (int i = 0; i < thirdPartyRechargeOrderList.size(); i++) {
            ThirdPartyRechargeOrder order = thirdPartyRechargeOrderList.get(i);
            if (order.getCreateTime().getTime() > beginTime && statusSet.contains(order.getOrderStatus())) {
                account += order.getAmount();
            }
        }

        return account;
    }

    /**
     * 获取近期增加的vip经验
     * @param time
     * @return
     */
    public long getRecentAddVipExp(long time) {
        long beginTime = System.currentTimeMillis() - time;
        long addVipExp = 0L;
        for (int i = 0; i < rechargeOrderList.size(); i++) {
            RechargeOrder order = rechargeOrderList.get(i);
            if (order.getOrderStatus() == eOrderStatus.HasBeenCharged && order.getCreateTime().getTime() >= beginTime) {
                addVipExp += order.getAddVipExp();
            }
        }
        return addVipExp;
    }

    public long getRechargeAccount(){
        long account = 0L;
        for (int i = 0; i < rechargeOrderList.size(); i++) {
            RechargeOrder order = rechargeOrderList.get(i);
            if(order.getOrderStatus() != eOrderStatus.HasBeenCharged && order.getOrderStatus() != eOrderStatus.ReturnIngots) {
                continue;
            }
            account += order.getAmount();

        }
        return account;
    }

    public long getThirdRechargeAccount(){
        long account = 0L;
        for (int i = 0; i < thirdPartyRechargeOrderList.size(); i++) {
            ThirdPartyRechargeOrder order = thirdPartyRechargeOrderList.get(i);
            if(order.getOrderStatus() != eOrderStatus.HasBeenCharged && order.getOrderStatus() != eOrderStatus.ReturnIngots) {
                continue;
            }
            account += order.getAmount();

        }
        return account;
    }

    public Map<String, Integer> getRechargeDaysFromOrder(){
        Map<String, Integer> map = new HashedMap();
        for (int i = 0; i < rechargeOrderList.size(); i++) {
            RechargeOrder order = rechargeOrderList.get(i);
            if(order.getOrderStatus() != eOrderStatus.HasBeenCharged && order.getOrderStatus() != eOrderStatus.ReturnIngots){
                continue;
            }
            if(order.getCreateTime() == null){
                continue;
            }
            String dayStr = DateHelper.getPyyyyMMddDateString(order.getCreateTime().getTime() / 1000);
            map.put(dayStr, 1);
        }
        return map;
    }

    public Map<String, Integer> getRechargeDaysFromThridPartOrder(){
        Map<String, Integer> map = new HashedMap();
        for (int i = 0; i < thirdPartyRechargeOrderList.size(); i++) {
            ThirdPartyRechargeOrder order = thirdPartyRechargeOrderList.get(i);
            if(order.getOrderStatus() != eOrderStatus.HasBeenCharged && order.getOrderStatus() != eOrderStatus.ReturnIngots){
                continue;
            }
            if(order.getCreateTime() == null){
                continue;
            }
            String dayStr = DateHelper.getPyyyyMMddDateString(order.getCreateTime().getTime() / 1000);
            map.put(dayStr, 1);
        }
        return map;
    }

    //获取玩家7日内的所有充值订单
    public List<RechargeOrder> getRecharge7DaysFromOrder(){
        List<RechargeOrder> list = new ArrayList<>();
        for (int i = 0; i < rechargeOrderList.size(); i++) {
            RechargeOrder order = rechargeOrderList.get(i);
            if(order.getCreateTime().getTime() + DateHelper.DAY_MILLIONS * 7 > System.currentTimeMillis())
                if(order.getOrderStatus().getValue() == eOrderStatus.HasBeenCharged.getValue()
                        || order.getOrderStatus().getValue() == eOrderStatus.ReturnIngots.getValue()){
                    list.add(order);
                }
        }
        return list;
    }
    //获取玩家7日内的所有第三方充值订单
    public List<ThirdPartyRechargeOrder> getRecharge7DaysFromThridPartOrder(){
        List<ThirdPartyRechargeOrder> list = new ArrayList<>();
        for (int i = 0; i < thirdPartyRechargeOrderList.size(); i++) {
            ThirdPartyRechargeOrder order = thirdPartyRechargeOrderList.get(i);
            if(order.getCreateTime().getTime() + DateHelper.DAY_MILLIONS * 7 > System.currentTimeMillis())
                if(order.getOrderStatus().getValue() == eOrderStatus.HasBeenCharged.getValue()
                        || order.getOrderStatus().getValue() == eOrderStatus.ReturnIngots.getValue()){
                    list.add(order);
                }
        }
        return list;
    }

    /**
     * 现金礼包
     */
    public void notifyRMBMallActivity(int mallId){
        player.notifyListener(eGamePlayerEventType.RechargeBankSkin.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeBuildingUpgrade.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeHouseUpgrade.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargePatronsBreak.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeChildTrain.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeTravel.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeBeautyCount.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeThroughPass.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeEstateMoveFloor.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeTradeWarChallenge.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeOrangePatronsCount.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeLotteryTimes.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeClinicCureCount.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeDrugStore.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeWineShopReceptionCount.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeManor.getValue(), new ManorRechargeArgs(0, mallId));
        player.notifyListener(eGamePlayerEventType.RechargeZsOpen.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeInn.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeTitle.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeGrandChild.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeWineryMake.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeNewPlayerVehiclePackage.getValue(), mallId);

        player.notifyListener(eGamePlayerEventType.RechargePotentialAnd.getValue(), new PotentialArg(false, mallId));
        player.notifyListener(eGamePlayerEventType.RechargePotentialOr.getValue(), new PotentialArg(false, mallId));

        player.notifyListener(eGamePlayerEventType.RechargeBuildingUpgradeNew.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargePatronsBreakNew.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeChildTrainNew.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeTravelNew.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeBeautyCountNew.getValue(), mallId);

        player.notifyListener(eGamePlayerEventType.RechargeEstateMoveFloorNew.getValue(), mallId);

        player.notifyListener(eGamePlayerEventType.RechargeLotteryTimesNew.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeClinicCureCountNew.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeDrugStoreNew.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeWineShopReceptionCountNew.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeManorNew.getValue(), new ManorRechargeArgs(0, mallId));
        player.notifyListener(eGamePlayerEventType.RechargeZsReward.getValue(), mallId);


        player.notifyListener(eGamePlayerEventType.RechargeGrandChildNew.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeWineryMakeNew.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.RechargeCricketTrain.getValue(), mallId);

        player.notifyListener(eGamePlayerEventType.RechargeVehicleSoulBlock.getValue(), mallId);

        player.notifyListener(eGamePlayerEventType.RechargeTrigger.getValue(), mallId);

        player.notifyListener(eGamePlayerEventType.RechargeWingRoomChakra.getValue(), mallId);

        player.notifyListener(eGamePlayerEventType.CurioRechargeTrigger.getValue(), mallId);

        player.notifyListener(eGamePlayerEventType.RechargeMusicRoom.getValue(), mallId);

        player.notifyListener(eGamePlayerEventType.VehicleBoneRechargeTrigger.getValue(), mallId);
    }

    /**
     * 系统开放现金礼包
     */
    public void notifySystemOpenRMBMallActivity(int mallId){
        player.notifyListener(eGamePlayerEventType.WingRoomSystemOpenRechargeTrigger.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.ManorFishPondSystemOpenRechargeTrigger.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.CricketSystemOpenRechargeTrigger.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.VehicleSoulSystemOpenRechargeTrigger.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.WinerySystemOpenRechargeTrigger.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.GrandChildSystemOpenRechargeTrigger.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.MusicRoomSystemOpenRechargeTrigger.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.CurioSystemOpenRechargeTrigger.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.VehicleBoneSystemOpenRechargeTrigger.getValue(), mallId);
    }

    public void notifyNewRechargeActivity(int mallId) {
        player.notifyListener(eGamePlayerEventType.DailyDiscountOneKeyBuy.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.WealthGodGifts.getValue(), mallId);
        player.notifyListener(eGamePlayerEventType.ServerOpenGifts.getValue(), mallId);
    }

    //通知聯盟活動
    private void notifyUnionActivity(long vipExp){
        UnionRechargeUserArgs unionRechargeUserArgs = new UnionRechargeUserArgs(UnionRechargeUserArgs.VALUE_IN, (int) vipExp,player.getUserInfo().getUnionUid(),player.getUserId());
        player.notifyListener(eGamePlayerEventType.UnionRechargeUser.getValue(), unionRechargeUserArgs);
        if(!StringUtils.isNullOrEmpty(player.getUserInfo().getUnionUid())){
            UnionActivityMgr.notifyAllMemberActivity(player.getUserInfo().getUnionUid(),player.getUserId(),eGamePlayerEventType.UnionRechargeUser.getValue());
        }
    }


    public static int adminRechagetCheck(List<Integer> mallIds){
        for(int mallId : mallIds){
            MallInfo mallInfo = MallMgr.getMallInfoByMallId(mallId);
            long money = 0;
            if(null != mallInfo){
                money = MallRechargeConfigMgr.getPrice(mallInfo);
//                money = Long.parseLong(mallInfo.getPrice());
            }
            if (null == mallInfo || 0 == money) {
                return GameErrorCode.E_MALL_NO_EXIST;
            }
            if(mallInfo.getShopType() != eShopType.IngotsMall.getValue()){
                return GameErrorCode.E_MALL_GOODS_TYPE_ERROR;
            }
        }
        return 0;
    }

    public final int adminRecharge(int mallId, int num) {
        MallInfo mallInfo = MallMgr.getMallInfoByMallId(mallId);
        int activityId = 0;
        if(null != mallInfo){
            activityId = mallInfo.getActivityId();
        }
        ActivityInfo activityInfo = ActivityMgr.getOpenActivityInfo(activityId);
        if(mallInfo.getShopType() == eShopType.IngotsMall.getValue()){
            for(int i=0;i<num;i++){
                BaseRecharge baseRecharge = BaseRecharge.getBaseChargeLogic(player, mallInfo, activityInfo);
                if(null != baseRecharge) {
                    baseRecharge.recharge("adminRecharge", rechargeOrderList, thirdPartyRechargeOrderList,
                            false, true, null);
                }
            }
        }else{
            return GameErrorCode.E_MALL_GOODS_TYPE_ERROR;
        }
//        LogMgr.addLogRecharge(player.getUserId(), mallInfo.getMallId(), num, Integer.valueOf(mallInfo.getPrice()), "adminRecharge",
//                GameServer.getInstance().getServerId());
        return 0;
    }

    /**
     * 最近7日订单最大金额
     */
    public long lastSevenDayOrderPrice(){
        List<RechargeOrder> lastOrderList = new ArrayList<>();
        for(RechargeOrder order : rechargeOrderList){
            if(DateHelper.calc2DateTDOADays(order.getCreateTime(), new Date()) <= 7){
                lastOrderList.add(order);
            }
        }
        List<ThirdPartyRechargeOrder> lastThirdOrderList = new ArrayList<>();
        for(ThirdPartyRechargeOrder order : thirdPartyRechargeOrderList){
            if(DateHelper.calc2DateTDOADays(order.getCreateTime(), new Date()) <= 7){
                lastThirdOrderList.add(order);
            }
        }
        long price = 0;
        for(RechargeOrder order : lastOrderList){
            if(order.getAmount() > price){
                price = order.getAmount();
            }
        }
        for(ThirdPartyRechargeOrder order : lastThirdOrderList){
            if(order.getAmount() > price){
                price = order.getAmount();
            }
        }
        return price;
    }

    /**
     * 获取最近7日订单的最大档位金额(充值成功)
     *
     * @return
     */
    public long lastSevenDayMaxRechargeLv() {
        List<RechargeOrder> lastOrderList = new ArrayList<>();
        for (RechargeOrder order : rechargeOrderList) {
            if (order.getOrderStatus() == eOrderStatus.HasBeenCharged && DateHelper.calc2DateTDOADays(order.getCreateTime(), new Date()) <= 7) {
                lastOrderList.add(order);
            }
        }
        List<ThirdPartyRechargeOrder> lastThirdOrderList = new ArrayList<>();
        for (ThirdPartyRechargeOrder order : thirdPartyRechargeOrderList) {
            if (order.getOrderStatus() == eOrderStatus.HasBeenCharged && DateHelper.calc2DateTDOADays(order.getCreateTime(), new Date()) <= 7) {
                lastThirdOrderList.add(order);
            }
        }
        long price = 0;
        for (RechargeOrder order : lastOrderList) {
            if (order.getAmount() > price) {
                price = order.getAmount();
            }
        }
        for (ThirdPartyRechargeOrder order : lastThirdOrderList) {
            if (order.getAmount() > price) {
                price = order.getAmount();
            }
        }
        return price;
    }

    /**
     * 描述：发放代金币
     * 作者：zrq
     * 时间：2022/8/9
     * 参数：
     第三方订单对象
     * 返回值：
     **/
    private void sendGoldTokenOther(ThirdPartyRechargeOrder thirdPartyRechargeOrder) {
        Property mailReward = new Property(GameConfig.GAME_MONEY_INGOTS, BigInteger.valueOf(thirdPartyRechargeOrder.getExtraIngots()));
        mailReward.addProperty(eItemId.GOLD_TOKEN.getValue(), BigInteger.valueOf(thirdPartyRechargeOrder.getRealIngots()));
        String mailTitle = MultipleLanguageMgr.getContent(MailManager.GOLD_TOKEN_RECHARGE_TITLE, player.getLanguage());
        String mailContent = MultipleLanguageMgr.getContent(MailManager.GOLD_TOKEN_RECHARGE_CONTENT, player.getLanguage());
        MailManager.sendMail(player.getUserId(), eMailType.SYSTEM.getValue(), PropertyHelper.parsePropertyToString(mailReward),
                mailContent, mailTitle);
    }

    private void sendGoldToken(ThirdPartyRechargeOrder thirdPartyRechargeOrder) {
        Property mailReward = new Property();
        if (thirdPartyRechargeOrder.getSubCoinType() == 0) {
            // 元宝
            mailReward.addProperty(GameConfig.GAME_MONEY_INGOTS, BigInteger.valueOf(thirdPartyRechargeOrder.getRealIngots()));
        } else {
            // 通宝
            mailReward.addProperty(eItemId.GOLD_TOKEN.getValue(), BigInteger.valueOf(thirdPartyRechargeOrder.getRealIngots()));
        }
        if (thirdPartyRechargeOrder.getExtraCoinType() == 0) {
            // 元宝
            mailReward.addProperty(GameConfig.GAME_MONEY_INGOTS, BigInteger.valueOf(thirdPartyRechargeOrder.getExtraIngots()));
        } else {
            // 通宝
            mailReward.addProperty(eItemId.GOLD_TOKEN.getValue(), BigInteger.valueOf(thirdPartyRechargeOrder.getExtraIngots()));
        }
        String mailTitle = MultipleLanguageMgr.getContent(MailManager.GOLD_TOKEN_RECHARGE_TITLE, player.getLanguage());
        String mailContent = MultipleLanguageMgr.getContent(MailManager.GOLD_TOKEN_RECHARGE_CONTENT, player.getLanguage());
        MailManager.sendMail(player.getUserId(), eMailType.SYSTEM.getValue(), PropertyHelper.parsePropertyToString(mailReward),
                mailContent, mailTitle);

        try {
            //日志
            long originalValue = player.getUserInfo().getVipExp();
            long addVip = 0;
            LogMgr.addLogRecharge(player.getUserId(), 0, 1, thirdPartyRechargeOrder.getAmount(), thirdPartyRechargeOrder.getPlatformOrderNo(),
                    GameServer.getInstance().getServerId(), 1, thirdPartyRechargeOrder.getSdkOrderNo(), player.getUserInfo().getVipExp(), "",
                    thirdPartyRechargeOrder.getCurrency(), thirdPartyRechargeOrder.getRealMoney(), thirdPartyRechargeOrder.getRealCurrency(),
                    thirdPartyRechargeOrder.getLocalMoney(), thirdPartyRechargeOrder.getLocalCurrency(), thirdPartyRechargeOrder.getLtrRate(),
                    thirdPartyRechargeOrder.getNewMoney(), thirdPartyRechargeOrder.getTax(), thirdPartyRechargeOrder.getProductCoin(),
                    thirdPartyRechargeOrder.getDevice(), thirdPartyRechargeOrder.getPayChannel(), thirdPartyRechargeOrder.getPlatformOrderNo(),
                    thirdPartyRechargeOrder.getActivityId(), thirdPartyRechargeOrder.getCouponMoney(), 0, false);
            AutoLogMgr.add(new LogVipExp(player.getUserId(), originalValue, addVip, originalValue + addVip, 0, "第三方元宝充值"));//第三方元宝充值
        } catch (Exception e) {
            log.error("sendGoldToken记录日志错误", e);
        }
    }

    public GoldTokenRechargeResult goldTokenRecharge(MallInfo mallInfo, ActivityInfo activityInfo){
        GoldTokenRechargeResult goldTokenRechargeResult = new GoldTokenRechargeResult();
        BaseRecharge baseRecharge = BaseRecharge.getBaseChargeLogic(player, mallInfo, activityInfo);
        if(null == baseRecharge){
            goldTokenRechargeResult.setRet(GameErrorCode.E_MALL_LIMIT_BUY);
            return goldTokenRechargeResult;
        }
        RechargeResult rechargeResult = baseRecharge.recharge("gold token", rechargeOrderList, thirdPartyRechargeOrderList,
                false, false, null);
        if(rechargeResult.isRepeatedBuy()){
            goldTokenRechargeResult.setRet(GameErrorCode.E_MALL_LIMIT_BUY);
            return goldTokenRechargeResult;
        }
        player.getModule(ActivityMallModule.class).addMallBuyCount(mallInfo, 1);

        goldTokenRechargeResult.setReward(rechargeResult.getReward());
        return goldTokenRechargeResult;
    }

    /**
    * 描述：处理未找到商品信息的订单返通宝
    * 作者：zrq
    * 时间：2022/11/17
    * 参数：

    * 返回值：
    **/
    private int dealMallNoFindReturnGoldToken(RechargeOrder rechargeOrder, boolean isAddToList){
        rechargeOrder.setOrderStatus(eOrderStatus.ReturnIngots);
        if(rechargeOrder.getReturnIngots() > 0 && rechargeOrder.getAddVipExp() > 0) {
            if (RechargeBussiness.updateRechargeOrderStatus(rechargeOrder)) {
                MallMgr.mallNoFindReturnGoldToken(player, rechargeOrder.getMallName(), rechargeOrder.getCreateTime(), rechargeOrder.getAddVipExp());
                //通知客户端到账
                notifyClientRechargeSuccess(rechargeOrder.getMallId(), true, rechargeOrder);
                log.warn("订单:{} 购买活动商品未找到:{},返还通宝:{},playerId:{}", rechargeOrder.getOrderNo(), rechargeOrder.getMallId(),
                        rechargeOrder.getAddVipExp(), player.getUserId());

                LogMgr.addLogRecharge(player.getUserId(), rechargeOrder.getMallId(), 1, rechargeOrder.getAmount(), rechargeOrder.getPlatformOrderNo(),
                        GameServer.getInstance().getServerId(), 0, rechargeOrder.getSdkOrderNo(), player.getUserInfo().getVipExp(), "",
                        rechargeOrder.getCurrency(), rechargeOrder.getRealMoney(), rechargeOrder.getRealCurrency(), rechargeOrder.getLocalMoney(),
                        rechargeOrder.getLocalCurrency(), rechargeOrder.getLtrRate(), rechargeOrder.getNewMoney(), rechargeOrder.getTax(),
                        rechargeOrder.getProductCoin(), rechargeOrder.getDevice(), rechargeOrder.getPayChannel(), rechargeOrder.getPlatformOrderNo(),
                        rechargeOrder.getActivityId(), rechargeOrder.getCouponMoney(), rechargeOrder.getMallMarkId(), true);

                //设置一下重复购买状态
                rechargeOrder.setRepeatBuy(true);
                if(!changeRepeatMap.containsKey(rechargeOrder.getOrderNo())) {
                    changeRepeatMap.put(rechargeOrder.getOrderNo(), rechargeOrder);
                }

                //添加到充值列表中
                if (isAddToList) {
                    rechargeOrderList.add(rechargeOrder);
                }
                return 0;
            }
        }
        return GameErrorCode.E_RECHARGE_FAIL;
    }

    public void syncSubscribe(UserSubscribe userSubscribe){
        if(null != userSubscribe){
            List<UserSubscribe> dataList = new ArrayList<>();
            dataList.add(userSubscribe);
            syncSubscribeList(dataList, false);
        }
    }

    public void syncSubscribeList(List<UserSubscribe> dataList, boolean isLogin){
        SubscribeProto.SubscribeListMsg.Builder listMsg = SubscribePb.parseSubscribeListMsg(dataList);
        if(isLogin){
            player.sendPacket(Protocol.U_SUBSCRIBE_LIST, listMsg);
        }else {
            player.sendPacket(Protocol.U_SUBSCRIBE_SYNC, listMsg);
        }
    }

    public Map<Integer, UserSubscribe> getUserSubscribeMap() {
        return userSubscribeMap;
    }

    public synchronized void addSubscribe(int mallId, int type, boolean isFree, long expiresTime, String orderNo){
        if(!userSubscribeMap.containsKey(mallId)){
            UserSubscribe userSubscribe = new UserSubscribe();
            userSubscribe.setUserId(player.getUserId());
            userSubscribe.setMallId(mallId);
            userSubscribe.setInsertOption();
            userSubscribeMap.put(mallId, userSubscribe);
        }
        UserSubscribe userSubscribe = userSubscribeMap.get(mallId);
        userSubscribe.setType(type);
        userSubscribe.setFree(isFree);
        userSubscribe.setExpiresTime(expiresTime);
        userSubscribe.setOrderNo(orderNo);
        userSubscribe.setModifyTime(new Date());
        syncSubscribe(userSubscribe);
    }

    /**
     * 处理十日充值打包购买的逻辑
     */
    public int dealPackageTenDayDiscountMall(int activityId){
        ActivityModule activityModule = player.getModule(ActivityModule.class);
        BaseActivityData baseActivityData = activityModule.getBaseActivityData(activityId);
        if(null == baseActivityData){
            return GameErrorCode.E_TEN_DAY_DISCOUNT_CONDITION_ERROR;
        }
        //遍历玩家身上的活动条件数据 全部设置1
        for (UserActivityConditionData conditionData:baseActivityData.getUserActivityConditionDataList()){
            //十日特惠礼包
            if (eGamePlayerEventType.TenDayDiscount.getValue() == conditionData.getType()){
                conditionData.setValue(BigInteger.ONE);
            }
        }
        return 0;
    }

    /**
    * 检测是否可以打包购买十日特惠礼包
    */
    public int checkCanBuyPackageTenDayDisCountMall(int activityId){
        Map<Integer, MallInfo> mallInfoTypeMap = NormalActivityMgr.getMallInfoTypeMap(activityId, eShopType.TenDaysDiscountMall.getValue());
        ActivityMallModule module = player.getModule(ActivityMallModule.class);
        for (MallInfo mallInfo : mallInfoTypeMap.values()){
            if (mallInfo.getExtendParam().equals("0")){
                continue;
            }
            if (module.isOverLimitBuyCount(mallInfo, 1)){
                return GameErrorCode.E_TEN_DAY_DISCOUNT_MALL_HAS_BUY_SEPARATELY;
            }
        }
        ActivityModule activityModule = player.getModule(ActivityModule.class);
        BaseActivityData baseActivityData = activityModule.getBaseActivityData(activityId);
        if(null == baseActivityData){
            return GameErrorCode.E_TEN_DAY_DISCOUNT_CONDITION_ERROR;
        }
        //遍历玩家身上的活动条件数据
        for (UserActivityConditionData conditionData:baseActivityData.getUserActivityConditionDataList()){
            if (conditionData.getValue().compareTo(BigInteger.ZERO) > 0 || conditionData.isGetReward()){
                return GameErrorCode.E_TEN_DAY_DISCOUNT_MALL_HAS_BUY_SEPARATELY;
            }
        }
        return 0;
    }



    /**
     * 检测是否可以拆分购买十日特惠礼包
     * @param activityId
     * @param day
     * @param mallLevel
     * @return
     */
        
    public int checkCanSeparatelyBuyTenDayDiscountMall(int activityId, int day, int mallLevel){
        UserActivityConditionData userActivityConditionData = getUserTenDayDiscountActivityConditionData(activityId, day, mallLevel);
        if (userActivityConditionData == null){
            return GameErrorCode.E_TEN_DAY_DISCOUNT_CONDITION_ERROR;
        }
        if (userActivityConditionData.getValue().compareTo(BigInteger.ZERO) > 0){
            return GameErrorCode.E_TEN_DAY_DISCOUNT_MALL_HAS_BUY;
        }
        if (userActivityConditionData.isGetReward()){
            return GameErrorCode.E_TEN_DAY_DISCOUNT_MALL_HAS_BUY;
        }
        ActivityInfo openActivityInfo = ActivityMgr.getOpenActivityInfo(activityId);
        long beginTime = openActivityInfo.getBeginTime();
        int i = DateHelper.calc2DateTDOADays(new Date(beginTime * DateHelper.SECOND_MILLIONS), new Date());
        if (i < day){
            return GameErrorCode.E_TEN_DAY_DISCOUNT_MALL_NO_ARRIVE_THIS_DAY;
        }
        NormalActivityMgr.getActivityInfo(activityId);

        return 0;
    }

    /**
     * 十日特惠礼包通过活动id和天数与类型获取对应的condition
     * @return
     */
    public UserActivityConditionData getUserTenDayDiscountActivityConditionData(int activityId,int day,int mallType){
        ActivityModule activityModule = player.getModule(ActivityModule.class);
        BaseActivityData baseActivityData = activityModule.getBaseActivityData(activityId);

        if(null == baseActivityData){
            return null;
        }
        //遍历玩家身上的活动条件数据
        for (UserActivityConditionData conditionData:baseActivityData.getUserActivityConditionDataList()){
            ActivityConditionInfo activityConditionInfo = NormalActivityMgr.getActivityConditionInfo(activityId, conditionData.getConditionId());
            if (activityConditionInfo==null){
                continue;
            }
            //判断是否是十日特惠礼包
            if (conditionData.getType() == eGamePlayerEventType.TenDayDiscount.getValue() &&
                    activityConditionInfo.getParamList().get(1).intValue() == mallType &&       //判断类型 1 3 6元
                    activityConditionInfo.getParamList().get(2).intValue() == day){             //判断天数
                return conditionData;
            }
        }
        return null;
    }

}
